package com.gfxy.educational.service;

import com.gfxy.educational.dao.EduJobTimeTypeMapper;
import com.gfxy.educational.entity.EduJobTimeType;
import com.gfxy.educational.entity.EduJobTimeTypeExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: lijixin 2019-05-24
 */
@Service
public class JobTimeTypeService {

    @Autowired
    private EduJobTimeTypeMapper jobTimeTypeMapper;

    public EduJobTimeType getCurrentTime() {

        EduJobTimeTypeExample example = new EduJobTimeTypeExample();
        example.createCriteria().andStateEqualTo(0);
        List<EduJobTimeType> jobTimeTypeList = jobTimeTypeMapper.selectByExample(example);
        if(jobTimeTypeList.size()!=1){
            throw new RuntimeException("没有正确的工作时间类型");
        } else {
            return jobTimeTypeList.get(0);
        }
    }

    /**
     * 更改工作时间
     * @param currectJobTimeType
     * @param futureJobTimeType
     */
    public void shiftJobTimeType(String currectJobTimeType,String futureJobTimeType) {
        EduJobTimeType jobTimeType = new EduJobTimeType();
        jobTimeType.setId(currectJobTimeType);
        jobTimeType.setState(1);
        jobTimeTypeMapper.updateByPrimaryKeySelective(jobTimeType);
        jobTimeType.setId(futureJobTimeType);
        jobTimeType.setState(0);
        jobTimeTypeMapper.updateByPrimaryKeySelective(jobTimeType);
    }
}
